/** *
  * Scala编程实战 P276
  *
  */

object collection1013 extends App {

  val a = Array(1, 2, 3, 4, 5)
  val b = Array("one", "two", "three", "four", "five")

  val new1 = for (e <- a) yield e
  println(new1.mkString("[", ",", "]"))

  val new2 = for (e <- a) yield e * 2
  println(new2.mkString("[", ",", "]"))

  val new3 = for (e <- a) yield e / 2
  println(new3.mkString("[", ",", "]"))

  val new4 = for (e <- b) yield e.toUpperCase()
  println(new4.mkString("[", ",", "]"))

  //for表达是中的if守卫
  val new5 = for (e <- b if e.length < 4) yield e.toUpperCase()
  println(new5.mkString("[", ",", "]"))

  val new6 = for (e <- b if e.length < 4 if e.startsWith("o")) yield e.toUpperCase()
  println(new6.mkString("[", ",", "]"))
}
